package com.l.d.app.library.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewTreeObserver;

import com.l.d.app.library.view.skinsupport.SkinCompatCircleImageView;

/**
 * Created by 林德 on 2017/4/8 8:52.
 * <p/>
 */
public class CircleColorView extends SkinCompatCircleImageView
{

    public CircleColorView(Context context)
    {
        this(context, null);
    }

    public CircleColorView(Context context, AttributeSet attrs)
    {
        this(context, attrs, 0);
    }

    public CircleColorView(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
        getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener()
        {
            @Override
            public boolean onPreDraw()
            {
                int width = getWidth();
                int height = getHeight();
                final int r = width > height ? height / 2 : width / 2;
                setBorderWidth(r);
                setImageResource(android.R.mipmap.sym_def_app_icon);
                getViewTreeObserver().removeOnPreDrawListener(this);
                return true;
            }
        });
    }
}
